//
//  SZTabBar.m
//  Weibo
//
//  Created by Zahi on 2017/7/22.
//  Copyright © 2017年 Zahi. All rights reserved.
//

#import "SZTabBar.h"

@interface SZTabBar ()

/**撰写按钮**/
@property (nonatomic, weak) UIButton *composeBtn;

@end

@implementation SZTabBar

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        
        [self setupUI];
    }
    return self;
}


#pragma mark - 布局子控件
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    _composeBtn.sz_centerX = self.sz_width * 0.5;
    _composeBtn.sz_centerY = self.sz_height * 0.5;
    
    CGFloat btnW = self.sz_width / 5;
    
    NSInteger i = 0;
    
    for (UIView *subview in self.subviews) {
        
        if ([subview isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            
            subview.sz_width = btnW;
            
            subview.sz_x = i * btnW;
            
            i = (i == 1) ? (i + 2 ) : (i + 1);
            
        }
    }
    

}

#pragma mark - 设置UI
- (void)setupUI {
    // 解决左边返回时的阴影
    self.backgroundImage = [UIImage imageNamed:@"tabbar_background"];
   
    UIButton *composeBtn = [[UIButton alloc] init];
    
    _composeBtn = composeBtn;
    
    [composeBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
    [composeBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
    
    [composeBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
    [composeBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
    
    [composeBtn sizeToFit];
    
    [self addSubview:composeBtn];
}


@end
